package pack.skys;

import java.util.concurrent.Callable;

import com.jme.image.Texture;
import com.jme.scene.Skybox;
import com.jme.scene.Spatial;
import com.jme.scene.Spatial.TextureCombineMode;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.TextureManager;
import com.jme.util.resource.ResourceLocatorTool;

@SuppressWarnings("serial")
public class DaySkyBox extends Skybox 
{
    private DisplaySystem disp = DisplaySystem.getDisplaySystem();    

	
	public DaySkyBox()
	{
		super("skybox", 100, 100, 100);
		
        Texture north = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "1.jpg"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture south = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "3.jpg"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture east = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "2.jpg"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture west = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "4.jpg"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture up = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "6.jpg"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture down = TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "5.jpg"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        
        setTexture(Skybox.Face.North, north);
        setTexture(Skybox.Face.West, west);
        setTexture(Skybox.Face.South, south);
        setTexture(Skybox.Face.East, east);
        setTexture(Skybox.Face.Up, up);
        setTexture(Skybox.Face.Down, down);
        
        Callable<Object> preload = new Callable<Object>() {
            public Object call() throws Exception {
                preloadTextures();
                return null;
            }
        };
        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER)
                .enqueue(preload);

        //updateRenderState();        
        
        CullState cullState = disp.getRenderer().createCullState();
        cullState.setCullFace(CullState.Face.None);
        cullState.setEnabled(true);
        setRenderState(cullState);

        ZBufferState zState = disp.getRenderer().createZBufferState();
        zState.setEnabled(false);
        setRenderState(zState);

        FogState fs = disp.getRenderer().createFogState();
        fs.setEnabled(false);
        setRenderState(fs);

        setLightCombineMode(Spatial.LightCombineMode.Off);
        setCullHint(Spatial.CullHint.Never);
        setTextureCombineMode(TextureCombineMode.Replace);
        updateRenderState();        
	}
}
